package model

import "gorm.io/gorm"

type School struct {
	gorm.Model
	Name         string `json:"name""`
	Province     string `json:"province""`
	City         string `json:"city""`
	Level        string `json:"level""`
	IsPublic     string `json:"is_public""`
	Is985        string `json:"is_985""`
	Is211        string `json:"is_211""`
	IsDoubleNice string `json:"is_double_nice""`
}

func FirstByName(name string) (first School) {
	db.First(&first, "name=?", name)
	return
}

func Create(school School) {
	db.Create(&school)
}

func Update(school School) {
	db.Where(&school, "name").Updates(school)
}

func UpdateOrCreate(school School) {
	isExist := FirstByName(school.Name)
	if isExist.Name != "" {
		Update(school)
	} else {
		Create(school)
	}
}
